using System.Collections.Generic;
using System.Threading.Tasks;
using Admin.NET.Application.Entity.Business;
using Admin.NET.Application.Service.Util.Dto;
using Admin.NET.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Admin.NET.Application.Service.Util;

[ApiDescriptionSettings(new string[] { "业务应用" }, Order = 100)]
public class UtilSetService : IDynamicApiController, ITransient, IPrivateDependency
{
	private readonly SqlSugarRepository<EWarehousing> _rep;

	private readonly SqlSugarRepository<BrandModel> _repInfo;

	private readonly UserManager _userManager;

	public UtilSetService(SqlSugarRepository<EWarehousing> rep, SqlSugarRepository<BrandModel> repInfo, UserManager userManager)
	{
		_rep = rep;
		_repInfo = repInfo;
		_userManager = userManager;
	}

	/// <summary>
	/// 修改提交
	/// </summary>
	/// <param name="input"></param>
	/// <returns></returns>
	[HttpPost("/util/sethousing")]
	[AllowAnonymous]
	public async Task SetHousing([FromBody] UtilHousingInput input)
	{
		EWarehousing model = _rep.GetFirst((EWarehousing u) => u.Sn == input.Sn);
		if (model == null)
		{
			EWarehousing entity = input.Adapt<EWarehousing>();
			await _rep.InsertAsync(entity);
			return;
		}
		model.BrandId = input.BrandId;
		model.Addr = input.Addr;
		model.IsMultiRate = input.IsMultiRate;
		model.ProtocolType = input.ProtocolType;
		await _rep.UpdateAsync(model);
	}

	/// <summary>
	/// 获取版本
	/// </summary>
	/// <returns></returns>
	[HttpGet("/util/getbrandmodellist")]
	[AllowAnonymous]
	[NonUnify]
	public async Task<List<BrandModel>> GetBrandModellist()
	{
		return await _repInfo.AsQueryable().ToListAsync();
	}
}
